package com.mcptt.config.user.profile.sub.sub;

import java.util.List;

import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;

import com.cloudptt.api.product.log.Log;

public class UserAlias
{
	public static final String Name = "UserAlias";
	private static final String Name_AliasEntry = "alias-entry";
	private static final String Namespace_Xml = "xml";
	private static final String Name_Lang = "lang";
	private String lang = "en-us";

	public String getAliasEntry() {
		return aliasEntry;
	}

	private String aliasEntry = "";

	public void parse(Element elem) throws JDOMException
	{
		if(elem == null)
		{
			return;
		}
		List<Element> list = elem.getChildren();//��ø��ڵ���ӽڵ�  
		for(Element subElem:list) 
		{
			String name = subElem.getName();
			Log.debug(this.getClass(), "name = " + name);
			if(name == null
					|| name.length() <= 0)
			{
				return;
			}
			if(name.equals(Name_AliasEntry))
			{
				Namespace namespace = subElem.getNamespace(Namespace_Xml);
				lang = subElem.getAttributeValue(Name_Lang,namespace);
				aliasEntry = subElem.getText();
			}
		}  
	}
	
	public String toString()
	{
		StringBuffer strBuf = new StringBuffer("\r\n");
		strBuf.append("<").append(Name).append(">").append("\r\n");
		
		strBuf.append("    ").append("<").append(Name_AliasEntry).append(" ");
		strBuf.append(Namespace_Xml).append(":").append(Name_Lang).append("=\"").append(lang).append("\">");
		strBuf.append(aliasEntry).append("</").append(Name_AliasEntry).append(">").append("\r\n");
		
		strBuf.append("</").append(Name).append(">").append("\r\n");

		return strBuf.toString();
	}
}
